<?php
class EditCategory extends Action {
	/*
	 * (non-PHPdoc) @see Action::execute()
	 */
	public function execute($params) {
		check_login ( ADMIN_LOGIN_PAGE );
		$cid = irqst ( 'cid' );
		$cateModel = new WebPageCategory ();
		if (empty ( $cid )) {
			$data ['page_tip_info'] = "<strong>出错啦!</strong>cid为空，系统无法加载对应频道栏目。";
		} else {
			$category = sess_del ( 'category_info', false );
			if (! $category) {
				$category = $cateModel->read ( $cid );
				$category ['up_name'] = $category ['up_cid'] ? $cateModel->get ( 'title', array (
						'cid' => $category ['up_cid'] 
				) ) : '顶级栏目';
			}
			if ($category == false) {
				$data ['page_tip_info'] = "<strong>出错啦!</strong>cid为{$cid}的频道栏目不存在。";
			} else {
				$data = $category;
				$data ['page_tip_info'] = sess_del ( 'page_tip_info' );
			}
		}		
		$data ['alert_cls'] = 1 == irqst ( 'suc', 0 ) ? 'alert-success' : 'alert-error';
		$data ['error'] = sess_del ( 'category_error', array () );
		$data ['error_cls'] = ModelValidator::getErrorCls ( $data ['error'] );
		$data ['editing'] = 1;
		$data ['treeNodes'] = json_encode ( $cateModel->getTreeNodes ( $cid ) );
		$data ['cate_types'] = apply_filter ( "get_category_types", array () );
		$data['navi_active'] = '编辑频道栏目';		
		return new SmartyView ( $data, 'vfs/CategoryForm' );
	}
}